#!/usr/bin/env python

# if you're a fastai developer please make sure you do this:
#
#    git clone https://github.com/fastai/fastai_docs
#    cd fastai_docs
#    tools/run-after-git-clone
#

import sys
if sys.hexversion < 0x03060000: sys.exit("!!! Please re-run this script with python-3.6 or higher")

import subprocess, os
from pathlib import Path

def run_script(script):

    cmd = f"{sys.executable} {script}"
    #print(f"Executing: {cmd}")
    result = subprocess.run(cmd.split(), shell=False, check=False,
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    if result.returncode != 0: print(f"Failed to execute: {cmd}")
    if result.stdout: print(f"{result.stdout.decode('utf-8')}")
    if result.stderr: print(f"Error: {result.stderr.decode('utf-8')}")

# make sure we are under the root of the project
cur_dir = Path(".").resolve().name
if (cur_dir == "tools"): os.chdir("..")

path = Path("tools")

# facilitate trusting of the repo-wide .gitconfig
run_script(path/"trust-origin-git-config")
